import Vue from 'vue';
import VueResource from 'vue-resource';

Vue.use(VueResource);

export default ({
  getData: function (path, param, callback) {
    Vue.http.get(Vue.prototype.$global.LOCAL_API_URL + path, {params: param}).then((response) => {
      Vue.prototype.$utils.indicatorClose();
      response = response.body;
      if (response.errorCode === 0) {
        callback(response.data);
      } else {
        Vue.prototype.$utils.toastMessage('访问数据出错');
      }
    }, (response) => {
      Vue.prototype.$utils.indicatorClose();
      Vue.prototype.$utils.toastMessage('系统错误，请联系系统管理员！');
    });
  },
  postData: function (path, param, callback) {
    Vue.http.post(Vue.prototype.$global.LOCAL_API_URL + path, param, callback).then((response) => {
      Vue.prototype.$utils.indicatorClose();
      response = response.body;
      if (response.errorCode === 0) {
        callback(response.data);
      } else {
        Vue.prototype.$utils.toastMessage('访问数据出错');
      }
    }, (response) => {
      Vue.prototype.$utils.indicatorClose();
      Vue.prototype.$utils.toastMessage('系统错误，请联系系统管理员！');
    });
  }
});
